package mamikeji.liaowa.http_api;

import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.io.File;
import java.util.Map;

import mamikeji.liaowa.utils.ForContents;
import mamikeji.liaowa.utils.ForPreference;
import okhttp3.Callback;

/**
 * Created by Jing on 2016/9/7.
 * 封装网络请求
 */
public class ForHttp {

    /**
     * 添加钥匙，token，设备类别
     *
     * @param urlString 链接
     * @param map       参数
     * @param Callback  回调监听
     */
    public static void setMsg(String urlString, Map<String, String> map, StringCallback Callback) {
        OkHttpUtils.post().url(urlString)
                .addHeader(HttpKey.EQUIPMENTID, ForPreference.getString(HttpKey.EQUIPMENTID))
                .addHeader(HttpKey.SOURCE, HttpKey.ANDROID)
                .addHeader(HttpKey.HEADER_TOKEN, ForPreference.getString(ForContents.USER_TOKEN))
                .params(map).build().execute(Callback);

    }

    /**
     * 添加钥匙，token，设备类别
     *
     * @param urlString 链接
     * @param Callback  回调监听
     */
    public static void getMsg(String urlString, StringCallback Callback) {
        OkHttpUtils.get().url(urlString)
                .addHeader(HttpKey.EQUIPMENTID, ForPreference.getString(HttpKey.EQUIPMENTID))
                .addHeader(HttpKey.SOURCE, HttpKey.ANDROID)
                .addHeader(HttpKey.HEADER_TOKEN, ForPreference.getString(ForContents.USER_TOKEN)).build().execute(Callback);
    }

    /**
     * 添加钥匙，token，设备类别
     *
     * @param urlString 链接
     * @param file      头像文件
     */
    public static void updateImage(String urlString, Map<String, String> map, File file, Callback callback) {
//        OkHttpUtils.post().url(urlString)
//                .addHeader(HttpKey.EQUIPMENTID, ForPreference.getString(HttpKey.EQUIPMENTID))
//                .addHeader(HttpKey.SOURCE, HttpKey.ANDROID)
//                .addHeader(HttpKey.HEADER_TOKEN, ForPreference.getString(ForContents.USER_TOKEN))
//                .addFile("image", file.getName(), file)
//                .params(map).build().execute(Callback);

        HttpUtils.doFile(urlString,
                file.getPath(), file.getName(), callback);
    }

}
